Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents TxtNumQuiz As System.Windows.Forms.TextBox Friend WithEvents BtnGo As System.Windows.Forms.Button Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents TxtTotal As System.Windows.Forms.TextBox Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents TxtAve As System.Windows.Forms.TextBox Friend WithEvents BtnClear As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.TxtNumQuiz = New System.Windows.Forms.TextBox Me.BtnGo = New System.Windows.Forms.Button Me.GroupBox1 = New System.Windows.Forms.GroupBox Me.GroupBox2 = New System.Windows.Forms.GroupBox Me.Label3 = New System.Windows.Forms.Label Me.TxtTotal = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.TxtAve = New System.Windows.Forms.TextBox Me.BtnClear = New System.Windows.Forms.Button Me.BtnQuit = New System.Windows.Forms.Button Me.GroupBox1.SuspendLayout() Me.GroupBox2.SuspendLayout() Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(224, 32) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(169, 49) Me.Label1.TabIndex = 0 Me.Label1.Text = "Quizzes" ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(8, 40) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(112, 24) Me.Label2.TabIndex = 1 Me.Label2.Text = "Number:" ' 'TxtNumQuiz ' Me.TxtNumQuiz.Location = New System.Drawing.Point(144, 40) Me.TxtNumQuiz.Name = "TxtNumQuiz" Me.TxtNumQuiz.Size = New System.Drawing.Size(88, 22) Me.TxtNumQuiz.TabIndex = 2 Me.TxtNumQuiz.Text = "" ' 'BtnGo ' Me.BtnGo.Location = New System.Drawing.Point(64, 96) Me.BtnGo.Name = "BtnGo" Me.BtnGo.Size = New System.Drawing.Size(104, 32) Me.BtnGo.TabIndex = 3 Me.BtnGo.Text = "Go" ' 'GroupBox1 ' Me.GroupBox1.Controls.Add(Me.Label2) Me.GroupBox1.Controls.Add(Me.TxtNumQuiz) Me.GroupBox1.Controls.Add(Me.BtnGo) Me.GroupBox1.Location = New System.Drawing.Point(32, 96) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(240, 176) Me.GroupBox1.TabIndex = 4 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Start" ' 'GroupBox2 ' Me.GroupBox2.Controls.Add(Me.BtnQuit) Me.GroupBox2.Controls.Add(Me.BtnClear) Me.GroupBox2.Controls.Add(Me.Label4) Me.GroupBox2.Controls.Add(Me.TxtAve) Me.GroupBox2.Controls.Add(Me.Label3) Me.GroupBox2.Controls.Add(Me.TxtTotal) Me.GroupBox2.Location = New System.Drawing.Point(304, 96) Me.GroupBox2.Name = "GroupBox2" Me.GroupBox2.Size = New System.Drawing.Size(304, 232) Me.GroupBox2.TabIndex = 5 Me.GroupBox2.TabStop = False Me.GroupBox2.Text = "Results" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(24, 40) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(112, 24) Me.Label3.TabIndex = 3 Me.Label3.Text = "Total Score" ' 'TxtTotal ' Me.TxtTotal.Location = New System.Drawing.Point(160, 40) Me.TxtTotal.Name = "TxtTotal" Me.TxtTotal.ReadOnly = True Me.TxtTotal.Size = New System.Drawing.Size(88, 22) Me.TxtTotal.TabIndex = 4 Me.TxtTotal.Text = "" ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(24, 88) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(112, 24) Me.Label4.TabIndex = 5 Me.Label4.Text = "Average" ' 'TxtAve ' Me.TxtAve.Location = New System.Drawing.Point(160, 88) Me.TxtAve.Name = "TxtAve" Me.TxtAve.ReadOnly = True Me.TxtAve.Size = New System.Drawing.Size(88, 22) Me.TxtAve.TabIndex = 6 Me.TxtAve.Text = "" ' 'BtnClear ' Me.BtnClear.Location = New System.Drawing.Point(32, 144) Me.BtnClear.Name = "BtnClear" Me.BtnClear.Size = New System.Drawing.Size(104, 40) Me.BtnClear.TabIndex = 7 Me.BtnClear.Text = "Clear" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(168, 144) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(104, 40) Me.BtnQuit.TabIndex = 8 Me.BtnQuit.Text = "Quit" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15) Me.ClientSize = New System.Drawing.Size(632, 448) Me.Controls.Add(Me.GroupBox2) Me.Controls.Add(Me.GroupBox1) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.GroupBox1.ResumeLayout(False) Me.GroupBox2.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click TxtNumQuiz.Text = "" TxtTotal.Text = "" TxtAve.Text = "" End Sub Private Sub BtnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGo.Click ' ensure that input is valid Dim quizzes As Integer If IsNumeric(TxtNumQuiz.Text) Then quizzes = Convert.ToInt32(TxtNumQuiz.Text) If quizzes > 0 And quizzes <= 15 Then ' got good input - loop that many times Dim cnt As Integer = 1 Dim sum As Integer = 0 ' loop through all of the quizzes ' NOTE would probably be easier with a for loop, but wanted to get in a point about infinite loops Do While cnt <= quizzes Dim curr As Integer Dim currStr As String currStr = InputBox("What is your score on quiz number " & cnt & "? ") ' check if valid input ' if so, update counter and accumulator ' probably should validate range of quiz scores too If IsNumeric(currStr) Then curr = Convert.ToInt32(currStr) sum = sum + curr ' accumulator cnt = cnt + 1 ' counter Else MsgBox("Please enter a number") End If Loop Dim ave As Double ave = sum / quizzes TxtTotal.Text = sum.ToString("n0") TxtAve.Text = ave.ToString("n1") Else MsgBox("The number of quizzes must be between 1 and 15") End If Else MsgBox("Please enter a number for number of quizzes") End If End Sub End Class